package com.example.service;

import com.example.dao.TypeDao;
import com.example.entity.Params;
import com.example.entity.Type;
import com.example.entity.dto.UserDTO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
@Slf4j
public class TypeService {

    @Resource
    private TypeDao typeDao;


    public void add(Type type) {
        typeDao.insertSelective(type);
    }

    public void update(Type type) {
        typeDao.updateByPrimaryKeySelective(type);
    }

    public PageInfo<Type> findBySearch(Params params) {
        // 开启分页查询
        PageHelper.startPage(params.getPageNum(), params.getPageSize());
        // 接下来的查询会自动按照当前开启的分页设置来查询
        List<Type> list = typeDao.findBySearch(params);
        log.info("{}",list);
        return PageInfo.of(list);
    }

    public void delete(Integer id) {
        typeDao.deleteByPrimaryKey(id);
    }

    public List<Type> findAll() {
        return typeDao.selectAll();
    }

    /**
     * 根据学号查找姓名
     * @param studentNumber
     * @return
     */
    public String getNameByNu(String studentNumber) {
        String name = typeDao.getNameByNu(studentNumber);
        return name;
    }

    public List<Type> findAllByStatus1(){
        return typeDao.find1();
    }
    public List<Type> findAllByStatus0(){
        return typeDao.find0();
    }

    public void updateStatus(UserDTO userDTO) {
        typeDao.updataStatusById(userDTO);
    }

    public String selectNumberByIdCard(String idCard) {
        return typeDao.selectNumberByIdCard(idCard);
    }
}
